package com.ryan.spring.cloud.gateway.model;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.cloud.gateway.filter.FilterDefinition;
import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition;

import java.util.List;

/**
 * Created by kaimin on 21/1/2019.
 * time : 18:14
 */

@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class GatewayDefine {
    private String id;

    private String uri;

    private String predicates;

    private String filters;



    public List<PredicateDefinition> getPredicateDefinition() {
        if (this.predicates != null) {
            List<PredicateDefinition> predicateDefinitionList = JSON.parseArray(this.predicates, PredicateDefinition.class);
            return predicateDefinitionList;
        } else {
            return null;
        }
    }

    public List<FilterDefinition> getFilterDefinition() {
        if (this.filters != null) {
            List<FilterDefinition> filterDefinitionList = JSON.parseArray(this.filters, FilterDefinition.class);
            return filterDefinitionList;
        } else {
            return null;
        }
    }



}
